using System;
using System.Data;
using System.Data.OleDb;
using System.Collections;
using System.Configuration;
using PCSComUtils.DataAccess;
using PCSComUtils.PCSExc;
using PCSComUtils.Common;
using System.Runtime.InteropServices;
namespace PCSComProduction.ValueAddTransact.DS
{
	public class PRO_LaborTimeDetailDS 
	{
		public PRO_LaborTimeDetailDS()
		{
		}
		private const string THIS = "PCSComProduction.ValueAddTransact.DS.PRO_LaborTimeDetailDS";
		/// <summary>
		/// This method uses to add data to PRO_LaborTimeDetail
		/// </summary>
		/// <param name="pobjObjectVO">PRO_LaborTimeDetailVO</param>
		public void Add(object pobjObjectVO)
		{
			const string METHOD_NAME = THIS + ".Add()";
			 
			OleDbConnection oconPCS =null;
			OleDbCommand ocmdPCS =null;
			try
			{
				PRO_LaborTimeDetailVO objObject = (PRO_LaborTimeDetailVO) pobjObjectVO;
				string strSql = String.Empty;
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand("", oconPCS);
				
				strSql=	"INSERT INTO PRO_LaborTimeDetail("
					+ PRO_LaborTimeDetailTable.EMPLOYEEID_FLD + ","
					+ PRO_LaborTimeDetailTable.STARTDATETIME_FLD + ","
					+ PRO_LaborTimeDetailTable.ENDDATETIME_FLD + ","
					+ PRO_LaborTimeDetailTable.HOUR_FLD + ","
					+ PRO_LaborTimeDetailTable.SHIFTID_FLD + ","
					+ PRO_LaborTimeDetailTable.HOURCODE_FLD + ","
					+ PRO_LaborTimeDetailTable.SETUPRUN_FLD + ","
					+ PRO_LaborTimeDetailTable.QUANTITY_FLD + ","
					+ PRO_LaborTimeDetailTable.COMPLETED_FLD + ","
					+ PRO_LaborTimeDetailTable.COMPLETEPERCENT_FLD + ","
					+ PRO_LaborTimeDetailTable.LABORCOSTCENTERID_FLD + ","
					+ PRO_LaborTimeDetailTable.WORKORDERMASTERID_FLD + ","
					+ PRO_LaborTimeDetailTable.WOROUTINGID_FLD + ","
					+ PRO_LaborTimeDetailTable.LABORTIMEMASTERID_FLD + ")"
					+ "VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_LaborTimeDetailTable.EMPLOYEEID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PRO_LaborTimeDetailTable.EMPLOYEEID_FLD].Value = objObject.EmployeeID;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_LaborTimeDetailTable.STARTDATETIME_FLD, OleDbType.Date));
				ocmdPCS.Parameters[PRO_LaborTimeDetailTable.STARTDATETIME_FLD].Value = objObject.StartDateTime;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_LaborTimeDetailTable.ENDDATETIME_FLD, OleDbType.Date));
				ocmdPCS.Parameters[PRO_LaborTimeDetailTable.ENDDATETIME_FLD].Value = objObject.EndDateTime;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_LaborTimeDetailTable.HOUR_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[PRO_LaborTimeDetailTable.HOUR_FLD].Value = objObject.Hour;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_LaborTimeDetailTable.SHIFTID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PRO_LaborTimeDetailTable.SHIFTID_FLD].Value = objObject.ShiftID;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_LaborTimeDetailTable.HOURCODE_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PRO_LaborTimeDetailTable.HOURCODE_FLD].Value = objObject.HourCode;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_LaborTimeDetailTable.SETUPRUN_FLD, OleDbType.Boolean));
				ocmdPCS.Parameters[PRO_LaborTimeDetailTable.SETUPRUN_FLD].Value = objObject.SetupRun;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_LaborTimeDetailTable.QUANTITY_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[PRO_LaborTimeDetailTable.QUANTITY_FLD].Value = objObject.Quantity;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_LaborTimeDetailTable.COMPLETED_FLD, OleDbType.Boolean));
				ocmdPCS.Parameters[PRO_LaborTimeDetailTable.COMPLETED_FLD].Value = objObject.Completed;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_LaborTimeDetailTable.COMPLETEPERCENT_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[PRO_LaborTimeDetailTable.COMPLETEPERCENT_FLD].Value = objObject.CompletePercent;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_LaborTimeDetailTable.LABORCOSTCENTERID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PRO_LaborTimeDetailTable.LABORCOSTCENTERID_FLD].Value = objObject.LaborCostCenterID;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_LaborTimeDetailTable.WORKORDERMASTERID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PRO_LaborTimeDetailTable.WORKORDERMASTERID_FLD].Value = objObject.WorkOrderMasterID;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_LaborTimeDetailTable.WOROUTINGID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PRO_LaborTimeDetailTable.WOROUTINGID_FLD].Value = objObject.WORoutingID;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_LaborTimeDetailTable.LABORTIMEMASTERID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PRO_LaborTimeDetailTable.LABORTIMEMASTERID_FLD].Value = objObject.LaborTimeMasterID;


				
				ocmdPCS.CommandText = strSql;
				ocmdPCS.Connection.Open();
				ocmdPCS.ExecuteNonQuery();	

			}
			catch(OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE)
				{
																   
					throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);				
				}
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
				}
			}			

			catch(InvalidOperationException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}
	

		/// <summary>
		/// This method uses to delete data from PRO_LaborTimeDetail
		/// </summary>
		/// <param name="pintID">PRO_LaborTimeDetailID</param>
		public void Delete(int pintID)
		{
			const string METHOD_NAME = THIS + ".Delete()";
			string strSql = String.Empty;
			strSql=	"DELETE " + PRO_LaborTimeDetailTable.TABLE_NAME + " WHERE  " + "WorkOrderDetailID" + "=" + pintID.ToString();
			OleDbConnection oconPCS=null;
			OleDbCommand ocmdPCS =null;
			try
			{
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);

				ocmdPCS.Connection.Open();
				ocmdPCS.ExecuteNonQuery();	
				ocmdPCS = null;

			}
			catch(OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLCASCADE_PREVENT_KEYCODE)
				{
																   
					throw new PCSDBException(ErrorCode.CASCADE_DELETE_PREVENT, METHOD_NAME, ex);				
				}
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
				}
			}			

			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}



			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}
	
		
		/// <summary>
		/// This method uses to get data from PRO_LaborTimeDetail
		/// </summary>
		/// <param name="pintID">ID</param>
		/// <returns>PRO_LaborTimeDetailVO</returns>
		public object GetObjectVO(int pintID)
		{
			const string METHOD_NAME = THIS + ".GetObjectVO()";
			DataSet dstPCS = new DataSet();
			
			OleDbDataReader odrPCS = null;
			OleDbConnection oconPCS = null;
			OleDbCommand ocmdPCS = null;
			try 
			{
				string strSql = String.Empty;
				strSql=	"SELECT "
					+ PRO_LaborTimeDetailTable.WORKORDERDETAILID_FLD + ","
					+ PRO_LaborTimeDetailTable.EMPLOYEEID_FLD + ","
					+ PRO_LaborTimeDetailTable.STARTDATETIME_FLD + ","
					+ PRO_LaborTimeDetailTable.ENDDATETIME_FLD + ","
					+ PRO_LaborTimeDetailTable.HOUR_FLD + ","
					+ PRO_LaborTimeDetailTable.SHIFTID_FLD + ","
					+ PRO_LaborTimeDetailTable.HOURCODE_FLD + ","
					+ PRO_LaborTimeDetailTable.SETUPRUN_FLD + ","
					+ PRO_LaborTimeDetailTable.QUANTITY_FLD + ","
					+ PRO_LaborTimeDetailTable.COMPLETED_FLD + ","
					+ PRO_LaborTimeDetailTable.COMPLETEPERCENT_FLD + ","
					+ PRO_LaborTimeDetailTable.LABORCOSTCENTERID_FLD + ","
					+ PRO_LaborTimeDetailTable.WORKORDERMASTERID_FLD + ","
					+ PRO_LaborTimeDetailTable.WOROUTINGID_FLD + ","
					+ PRO_LaborTimeDetailTable.LABORTIMEMASTERID_FLD
					+ " FROM " + PRO_LaborTimeDetailTable.TABLE_NAME
					+" WHERE " + PRO_LaborTimeDetailTable.WORKORDERDETAILID_FLD + "=" + pintID;

				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);

				ocmdPCS.Connection.Open();
				odrPCS = ocmdPCS.ExecuteReader();

				PRO_LaborTimeDetailVO objObject = new PRO_LaborTimeDetailVO();

				while (odrPCS.Read())
				{ 
					objObject.WorkOrderDetailID = int.Parse(odrPCS[PRO_LaborTimeDetailTable.WORKORDERDETAILID_FLD].ToString().Trim());
					objObject.EmployeeID = int.Parse(odrPCS[PRO_LaborTimeDetailTable.EMPLOYEEID_FLD].ToString().Trim());
					objObject.StartDateTime = DateTime.Parse(odrPCS[PRO_LaborTimeDetailTable.STARTDATETIME_FLD].ToString().Trim());
					objObject.EndDateTime = DateTime.Parse(odrPCS[PRO_LaborTimeDetailTable.ENDDATETIME_FLD].ToString().Trim());
					objObject.Hour = Decimal.Parse(odrPCS[PRO_LaborTimeDetailTable.HOUR_FLD].ToString().Trim());
					objObject.ShiftID = int.Parse(odrPCS[PRO_LaborTimeDetailTable.SHIFTID_FLD].ToString().Trim());
					objObject.HourCode = int.Parse(odrPCS[PRO_LaborTimeDetailTable.HOURCODE_FLD].ToString().Trim());
					objObject.SetupRun = bool.Parse(odrPCS[PRO_LaborTimeDetailTable.SETUPRUN_FLD].ToString().Trim());
					objObject.Quantity = Decimal.Parse(odrPCS[PRO_LaborTimeDetailTable.QUANTITY_FLD].ToString().Trim());
					objObject.Completed = bool.Parse(odrPCS[PRO_LaborTimeDetailTable.COMPLETED_FLD].ToString().Trim());
					objObject.CompletePercent = Decimal.Parse(odrPCS[PRO_LaborTimeDetailTable.COMPLETEPERCENT_FLD].ToString().Trim());
					objObject.LaborCostCenterID = int.Parse(odrPCS[PRO_LaborTimeDetailTable.LABORCOSTCENTERID_FLD].ToString().Trim());
					objObject.WorkOrderMasterID = int.Parse(odrPCS[PRO_LaborTimeDetailTable.WORKORDERMASTERID_FLD].ToString().Trim());
					objObject.WORoutingID = int.Parse(odrPCS[PRO_LaborTimeDetailTable.WOROUTINGID_FLD].ToString().Trim());
					objObject.LaborTimeMasterID = int.Parse(odrPCS[PRO_LaborTimeDetailTable.LABORTIMEMASTERID_FLD].ToString().Trim());

				}		
				return objObject;					
			}
			catch(OleDbException ex)
			{			
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}			

			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}


		/// <summary>
		/// This method uses to update data to PRO_LaborTimeDetail
		/// </summary>
		/// <param name="pobjObjecVO">PRO_LaborTimeDetailVO</param>
		public void Update(object pobjObjecVO)
		{
			const string METHOD_NAME = THIS + ".Update()";

			PRO_LaborTimeDetailVO objObject = (PRO_LaborTimeDetailVO) pobjObjecVO;
			

			//prepare value for parameters
			OleDbConnection oconPCS =null;
			OleDbCommand ocmdPCS = null;
			try 
			{
				string strSql = String.Empty;
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);
				strSql=	"UPDATE PRO_LaborTimeDetail SET "
					+ PRO_LaborTimeDetailTable.EMPLOYEEID_FLD + "=   ?" + ","
					+ PRO_LaborTimeDetailTable.STARTDATETIME_FLD + "=   ?" + ","
					+ PRO_LaborTimeDetailTable.ENDDATETIME_FLD + "=   ?" + ","
					+ PRO_LaborTimeDetailTable.HOUR_FLD + "=   ?" + ","
					+ PRO_LaborTimeDetailTable.SHIFTID_FLD + "=   ?" + ","
					+ PRO_LaborTimeDetailTable.HOURCODE_FLD + "=   ?" + ","
					+ PRO_LaborTimeDetailTable.SETUPRUN_FLD + "=   ?" + ","
					+ PRO_LaborTimeDetailTable.QUANTITY_FLD + "=   ?" + ","
					+ PRO_LaborTimeDetailTable.COMPLETED_FLD + "=   ?" + ","
					+ PRO_LaborTimeDetailTable.COMPLETEPERCENT_FLD + "=   ?" + ","
					+ PRO_LaborTimeDetailTable.LABORCOSTCENTERID_FLD + "=   ?" + ","
					+ PRO_LaborTimeDetailTable.WORKORDERMASTERID_FLD + "=   ?" + ","
					+ PRO_LaborTimeDetailTable.WOROUTINGID_FLD + "=   ?" + ","
					+ PRO_LaborTimeDetailTable.LABORTIMEMASTERID_FLD + "=  ?"
					+" WHERE " + PRO_LaborTimeDetailTable.WORKORDERDETAILID_FLD + "= ?";

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_LaborTimeDetailTable.EMPLOYEEID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PRO_LaborTimeDetailTable.EMPLOYEEID_FLD].Value = objObject.EmployeeID;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_LaborTimeDetailTable.STARTDATETIME_FLD, OleDbType.Date));
				ocmdPCS.Parameters[PRO_LaborTimeDetailTable.STARTDATETIME_FLD].Value = objObject.StartDateTime;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_LaborTimeDetailTable.ENDDATETIME_FLD, OleDbType.Date));
				ocmdPCS.Parameters[PRO_LaborTimeDetailTable.ENDDATETIME_FLD].Value = objObject.EndDateTime;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_LaborTimeDetailTable.HOUR_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[PRO_LaborTimeDetailTable.HOUR_FLD].Value = objObject.Hour;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_LaborTimeDetailTable.SHIFTID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PRO_LaborTimeDetailTable.SHIFTID_FLD].Value = objObject.ShiftID;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_LaborTimeDetailTable.HOURCODE_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PRO_LaborTimeDetailTable.HOURCODE_FLD].Value = objObject.HourCode;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_LaborTimeDetailTable.SETUPRUN_FLD, OleDbType.Boolean));
				ocmdPCS.Parameters[PRO_LaborTimeDetailTable.SETUPRUN_FLD].Value = objObject.SetupRun;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_LaborTimeDetailTable.QUANTITY_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[PRO_LaborTimeDetailTable.QUANTITY_FLD].Value = objObject.Quantity;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_LaborTimeDetailTable.COMPLETED_FLD, OleDbType.Boolean));
				ocmdPCS.Parameters[PRO_LaborTimeDetailTable.COMPLETED_FLD].Value = objObject.Completed;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_LaborTimeDetailTable.COMPLETEPERCENT_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[PRO_LaborTimeDetailTable.COMPLETEPERCENT_FLD].Value = objObject.CompletePercent;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_LaborTimeDetailTable.LABORCOSTCENTERID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PRO_LaborTimeDetailTable.LABORCOSTCENTERID_FLD].Value = objObject.LaborCostCenterID;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_LaborTimeDetailTable.WORKORDERMASTERID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PRO_LaborTimeDetailTable.WORKORDERMASTERID_FLD].Value = objObject.WorkOrderMasterID;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_LaborTimeDetailTable.WOROUTINGID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PRO_LaborTimeDetailTable.WOROUTINGID_FLD].Value = objObject.WORoutingID;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_LaborTimeDetailTable.LABORTIMEMASTERID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PRO_LaborTimeDetailTable.LABORTIMEMASTERID_FLD].Value = objObject.LaborTimeMasterID;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_LaborTimeDetailTable.WORKORDERDETAILID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PRO_LaborTimeDetailTable.WORKORDERDETAILID_FLD].Value = objObject.WorkOrderDetailID;


				ocmdPCS.CommandText = strSql;
				ocmdPCS.Connection.Open();
				ocmdPCS.ExecuteNonQuery();	
			}
			catch(OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE)
				{
																   
					throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);				
				}
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
				}
			}			

			catch(InvalidOperationException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}

		}


		/// <summary>
		/// This method uses to get all data from PRO_LaborTimeDetail
		/// </summary>
		/// <returns>DataSet</returns>
		public DataSet List()
		{
			const string METHOD_NAME = THIS + ".List()";
			DataSet dstPCS = new DataSet();
			
		

			OleDbConnection oconPCS =null;
			OleDbCommand ocmdPCS = null;
			try 
			{
				string strSql = String.Empty;
				
				strSql=	"SELECT "
					+ PRO_LaborTimeDetailTable.WORKORDERDETAILID_FLD + ","
					+ PRO_LaborTimeDetailTable.EMPLOYEEID_FLD + ","
					+ PRO_LaborTimeDetailTable.STARTDATETIME_FLD + ","
					+ PRO_LaborTimeDetailTable.ENDDATETIME_FLD + ","
					+ PRO_LaborTimeDetailTable.HOUR_FLD + ","
					+ PRO_LaborTimeDetailTable.SHIFTID_FLD + ","
					+ PRO_LaborTimeDetailTable.HOURCODE_FLD + ","
					+ PRO_LaborTimeDetailTable.SETUPRUN_FLD + ","
					+ PRO_LaborTimeDetailTable.QUANTITY_FLD + ","
					+ PRO_LaborTimeDetailTable.COMPLETED_FLD + ","
					+ PRO_LaborTimeDetailTable.COMPLETEPERCENT_FLD + ","
					+ PRO_LaborTimeDetailTable.LABORCOSTCENTERID_FLD + ","
					+ PRO_LaborTimeDetailTable.WORKORDERMASTERID_FLD + ","
					+ PRO_LaborTimeDetailTable.WOROUTINGID_FLD + ","
					+ PRO_LaborTimeDetailTable.LABORTIMEMASTERID_FLD
					+ " FROM " + PRO_LaborTimeDetailTable.TABLE_NAME;
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);
				ocmdPCS.Connection.Open();
				
				OleDbDataAdapter odadPCS = new OleDbDataAdapter(ocmdPCS);
				odadPCS.Fill(dstPCS,PRO_LaborTimeDetailTable.TABLE_NAME);

				return dstPCS;
			}
			catch(OleDbException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}			
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}


		}


		/// <summary>
		/// This method uses to update a DataSet
		/// </summary>
		/// <param name="pdstData">DataSet</param>
		public void UpdateDataSet(DataSet pdstData)
		{
			const string METHOD_NAME = THIS + ".UpdateDataSet()";
			string strSql;
			OleDbConnection oconPCS =null;
			OleDbCommandBuilder odcbPCS ;
			OleDbDataAdapter odadPCS = new OleDbDataAdapter();

			try
			{
				strSql=	"SELECT "
					+ PRO_LaborTimeDetailTable.WORKORDERDETAILID_FLD + ","
					+ PRO_LaborTimeDetailTable.EMPLOYEEID_FLD + ","
					+ PRO_LaborTimeDetailTable.STARTDATETIME_FLD + ","
					+ PRO_LaborTimeDetailTable.ENDDATETIME_FLD + ","
					+ PRO_LaborTimeDetailTable.HOUR_FLD + ","
					+ PRO_LaborTimeDetailTable.SHIFTID_FLD + ","
					+ PRO_LaborTimeDetailTable.HOURCODE_FLD + ","
					+ PRO_LaborTimeDetailTable.SETUPRUN_FLD + ","
					+ PRO_LaborTimeDetailTable.QUANTITY_FLD + ","
					+ PRO_LaborTimeDetailTable.COMPLETED_FLD + ","
					+ PRO_LaborTimeDetailTable.COMPLETEPERCENT_FLD + ","
					+ PRO_LaborTimeDetailTable.LABORCOSTCENTERID_FLD + ","
					+ PRO_LaborTimeDetailTable.WORKORDERMASTERID_FLD + ","
					+ PRO_LaborTimeDetailTable.WOROUTINGID_FLD + ","
					+ PRO_LaborTimeDetailTable.LABORTIMEMASTERID_FLD  + ","
					+ PRO_LaborTimeDetailTable.LABORTIMEDETAILID_FLD 
					+ "  FROM " + PRO_LaborTimeDetailTable.TABLE_NAME;

				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				odadPCS.SelectCommand = new OleDbCommand(strSql, oconPCS);
				odcbPCS = new OleDbCommandBuilder(odadPCS);
				pdstData.EnforceConstraints = false;
				odadPCS.Update(pdstData,PRO_LaborTimeDetailTable.TABLE_NAME);

			}
			catch(OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE)
				{
																   
					throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);				
				}
				else if (ex.Errors[1].NativeError == ErrorCode.SQLCASCADE_PREVENT_KEYCODE)
				{

					throw new PCSDBException(ErrorCode.CASCADE_DELETE_PREVENT, METHOD_NAME, ex);				
				}
				
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
				}
			}			

			catch(InvalidOperationException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}

		}
		/// <summary>
		/// Get all Labor Time detail data of Labor Time Master
		/// </summary>
		/// <param name="pintLaborTimeMasterID">Labor Time Master ID</param>
		/// <returns>All Labor Time detail data of Labor Time Master</returns>
		public DataSet GetDetailData(int pintLaborTimeMasterID)
		{
			const string METHOD_NAME = THIS + ".GetDetailData()";
			const string VIEW_PRO_LABORTIMEDETAIL = "v_Pro_LaborTimeDetail";
			DataSet dstPCS = new DataSet();
			OleDbConnection oconPCS =null;
			OleDbCommand ocmdPCS = null;
			try 
			{
				string strSql = String.Empty;
				/*
				strSql=	"SELECT "
					+ PRO_LaborTimeDetailTable.WORKORDERDETAILID_FLD + ","
					+ PRO_LaborTimeDetailTable.EMPLOYEEID_FLD + ","
					+ PRO_LaborTimeDetailTable.STARTDATETIME_FLD + ","
					+ PRO_LaborTimeDetailTable.ENDDATETIME_FLD + ","
					+ PRO_LaborTimeDetailTable.HOUR_FLD + ","
					+ PRO_LaborTimeDetailTable.SHIFTID_FLD + ","
					+ PRO_LaborTimeDetailTable.HOURCODE_FLD + ","
					+ PRO_LaborTimeDetailTable.SETUPRUN_FLD + ","
					+ PRO_LaborTimeDetailTable.QUANTITY_FLD + ","
					+ PRO_LaborTimeDetailTable.COMPLETED_FLD + ","
					+ PRO_LaborTimeDetailTable.COMPLETEPERCENT_FLD + ","
					+ PRO_LaborTimeDetailTable.LABORCOSTCENTERID_FLD + ","
					+ PRO_LaborTimeDetailTable.WORKORDERMASTERID_FLD + ","
					+ PRO_LaborTimeDetailTable.WOROUTINGID_FLD + ","
					+ PRO_LaborTimeDetailTable.LABORTIMEMASTERID_FLD
					+ " FROM " + PRO_LaborTimeDetailTable.TABLE_NAME
					+ " WHERE " + PRO_LaborTimeDetailTable.LABORTIMEMASTERID_FLD + "=" + pintLaborTimeMasterID;
				*/
				strSql = "SELECT * FROM " + VIEW_PRO_LABORTIMEDETAIL 
						+ " WHERE " + PRO_LaborTimeDetailTable.LABORTIMEMASTERID_FLD + "=" + pintLaborTimeMasterID;
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);
				ocmdPCS.Connection.Open();
				
				OleDbDataAdapter odadPCS = new OleDbDataAdapter(ocmdPCS);
				odadPCS.Fill(dstPCS,PRO_LaborTimeDetailTable.TABLE_NAME);

				return dstPCS;
			}
			catch(OleDbException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}			
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}
		/// <summary>
		/// Delete all Labor Time Detail by LaborTimeMasterID
		/// </summary>
		/// <param name="pintID">LaborTimeMasterID</param>
		public void DeleteByMasterID(int pintID)
		{
			const string METHOD_NAME = THIS + ".DeleteByMasterID()";
			string strSql = String.Empty;
			strSql=	"DELETE " + PRO_LaborTimeDetailTable.TABLE_NAME + " WHERE  " + PRO_LaborTimeDetailTable.LABORTIMEMASTERID_FLD + "=" + pintID.ToString();
			OleDbConnection oconPCS=null;
			OleDbCommand ocmdPCS =null;
			try
			{
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);

				ocmdPCS.Connection.Open();
				ocmdPCS.ExecuteNonQuery();	
				ocmdPCS = null;

			}
			catch(OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLCASCADE_PREVENT_KEYCODE)
				{
																   
					throw new PCSDBException(ErrorCode.CASCADE_DELETE_PREVENT, METHOD_NAME, ex);				
				}
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
				}
			}			

			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}



			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}
	}
}
